<?php
/*
 * 手机客户端 秀场展品列表接口
 * 传入参数 
 * 2013-12-011
 */
include "inc/public_header.php";
include "inc/MiniaturePro.class.php";
include "func/user.php";				//用户信息处理函数
include "func/pic.php";					//图片处理函数

//获取用户信息
$uInfoArr = user_getInfoFromUUID();
if(!$uInfoArr){
	echo json_encode(array("success"=>"0","errCode"=>"0"));
	die;
}
$uid = $uInfoArr["uid"]; //用户信息主键


$reJson = array();//构建返回值
 
$page			= $_REQUEST["page"]; 			//页数，第一页为0
$pagesize		= $_REQUEST["pagesize"];		//每页记录数
$hd_id			= $_REQUEST["hd_id"];			//活动主键

$panelWidth		= $_REQUEST["panelWidth"];		//屏幕宽度
if($panelWidth<480){
	$imgWidth  = 100;
}else if($panelWidth>=480 && $panelWidth<=600){
	$imgWidth = 200;
}else {
	$imgWidth = 300;
}

if(!isset($page)){
	$page = 0;
}
if(!isset($pagesize)){
	$pagesize = 20; //默认每页200条
}

$reJson["success"] = "1";

//作品总数
$sql = "select 
			count(a.id) as ct 
		from 
			new_weituo_zuopin a 
		where 
			a.uid = '".$uid."' and a.dr='0'
		";
if(isset($hd_id) && $hd_id!=""){
	$sql = $sql." and a.hd_id='".$hd_id."' ";
}
$db1->query($sql);
$db1->next_record();
$reJson["count"] = $db1->f("ct");


//作品信息列表
$sql ="select 
				a.id
				,a.aname
				,a.czln
				,a.pingfen
				,a.img_path
				,a.img_id
				,a.zan_count
				,a.aflag
				,a.jointype
				,a.pl_count
				,e.id as mini_img_id
				,e.awidth as mini_img_width
				,e.aheight as mini_img_height
				,e.aname as mini_img_aname
				,h.ct as gz_count
				,(SELECT aid from auction WHERE zpid=a.id) AS aid
		from 
				new_weituo_zuopin a	
				left join new_weituo_person d on a.uid=d.uid
				left join new_weituo_pic_size e on a.img_id=e.img_id and e.awidth='".$imgWidth."'
				left join (select count(0) as ct,zpid from new_weituo_gz group by zpid) h on a.id=h.zpid
		where
				a.dr='0'
				and a.uid='".$uid."'
		";
if(isset($hd_id) && $hd_id!=""){
	$sql = $sql." and a.hd_id='".$hd_id."' ";
}
$sql = $sql."limit ".($page * $pagesize).",".$pagesize;

$db->query($sql);
$worksArr = array();
$miniature = new MiniaturePro();	//构建缩略图处理类

while($db->next_record()){
	//处理生成缩略图
	$imgInfos = pic_resize(
							 $miniature
							,$db->f("img_path")
							,$db->f("mini_img_aname")
							,$imgWidth
							,$db->f("img_id")
							,$db->f("mini_img_id")
							,$db->f("mini_img_width")
							,$db->f("mini_img_height"));
	if($imgInfos["success"]=="0"){
		//图片有问题，无法显示
		$imgInfos["mini_img_url"] = "";
	}
	$canChange="1";
	if($db->f("aid")){
		$canChange="0";
	}
	$worksArr[] = array(
		"title"=>$db->f("aname")							//作品名称
		,"workId"=>$db->f("id")								//作品id
		,"imgUrl"=>$imgInfos["mini_img_url"]				//图片
		,"level"=>$db->f("pingfen")							//评分
		,"praiseCount"=>$db->f("zan_count")					//赞
		,"ideas"=>$db->f("czln")							//作品理念
		,"bidType"=>$db->f("jointype")						//竞拍类型 0展览1拍卖
		,"canChange"=>$canChange							//是否能竞拍状态修改 0可以1不能
		,"state"=>$db->f("aflag")							//审核状态
		,"replyCount"=>$db->f("pl_count")					//评论统计
		,"imgWidth"=>(string)$imgInfos["mini_img_width"]	//图片宽度
		,"imgHeight"=>(string)$imgInfos["mini_img_height"]	//图片高度
		,"worksCollection"=>$db->f("gz_count")?$db->f("gz_count"):"0"				//作品被收藏次数
	);
}
$reJson["list"]=$worksArr;
echo json_encode($reJson);
?>